﻿
@*$result = mysql_query($sql);
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// tinh tong so trang se hien thi
$maxPage = ceil($numrows/$rowsPerPage);

// hien thi lien ket den tung trang
$self = "index.php";
$nav  = '';

for($page = 1; $page <= $maxPage; $page++)
{
   if ($page == $pageNum)
   {
      $nav .= " $page "; // khong can tao link cho trang hien hanh
   }
   else
   {
      $nav .= " <a href=\"$self?page =$page\">$page</a> ";
   }
}

// tao lien ket den trang truoc & trang sau, trang dau, trang cuoi
if ($pageNum > 1)
{
   $page  = $pageNum - 1;
   $prev  = " <a href=\"$self?page =$page\">[Trang trước]</a> ";

   $first = " <a href=\"$self?page =1\">[Trang đầu]</a> ";
}
else
{
   $prev  = '&nbsp;'; // dang o trang 1, khong can in lien ket trang truoc
   $first = '&nbsp;'; // va lien ket trang dau
}

if ($pageNum < $maxPage)
{
   $page = $pageNum + 1;
   $next = " <a href=\"$self?page =$page\">[Trang kế]</a> ";

   $last = " <a href=\"$self?page =$maxPage\">[Trang cuối]</a> ";
}
else
{
   $next = '&nbsp;'; // dang o trang cuoi, khong can in lien ket trang ke
   $last = '&nbsp;'; // va lien ket trang cuoi
}
// hien thi cac link lien ket trang
?>
<div class="phantrang">
    <?
    echo "<center>". $first . $prev . $nav . $next . $last . "</center>";
    ?>
</div>*@     